package com.ttt.mapper.impl;

import com.ttt.mapper.RegisterInter;
import com.ttt.pojo.Student;
import com.ttt.utils.DbConnectionUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class RegisterMapperImpl implements RegisterInter {
    public void inSertS(Student student) throws SQLException {

        System.out.println("进入到RegisterMapperImpl");

        DbConnectionUtil dbConnectionUtil = new DbConnectionUtil();
        Connection connection = dbConnectionUtil.getConnection();
        String sql =" insert into studentsregister(id,name,gender,college,major,grade,phone,password) VALUES(" +
                " ?,?,?,?,?,?,?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,student.getId());
        preparedStatement.setString(2,student.getName());
        preparedStatement.setString(3,student.getGender());
        preparedStatement.setString(4,student.getCollege());
        preparedStatement.setString(5,student.getMajor());
        preparedStatement.setString(6,student.getGrade());
        preparedStatement.setString(7,student.getPhone());
        preparedStatement.setString(8,student.getPassword());
        int i = preparedStatement.executeUpdate();
        System.out.println("i =" + i);
        //关闭资源
        connection.close();
        preparedStatement.close();
        System.out.println("i" + i);
        System.out.println("mapper ok");

    }
}
